package com.example.cores_middle_activity;

import android.os.Bundle;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.Switch;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class SwtichActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_swtich);

        TextView tvSwitch = findViewById(R.id.tv_switch);
        Switch svView = findViewById(R.id.sv_view);

        svView.setOnCheckedChangeListener((compoundButton, b) -> {
            String format = String.format("当前状态：%s", b ? "开" : "关");
            tvSwitch.setText(format);
        });
    }
}